<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>ESMS</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/ssm_esms/static/css/font.css">
    <link rel="stylesheet" href="/ssm_esms/static/css/xadmin.css">
    <script type="text/javascript" src="/ssm_esms/static/js/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="/ssm_esms/static/lib/layui/layui.js"></script>
    <script type="text/javascript" src="/ssm_esms/static/js/xadmin.js"></script>

</head>

<body class="layui-anim layui-anim-up">

<div class="x-nav">
      <span class="layui-breadcrumb">
        <a>首页</a>
        <a>月考勤管理</a>
        <a>
          <cite>月考勤列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" id="container">
    <div class="layui-row">
        <div class="demoTable layui-col-md11 layui-form">
            员工工号：
            <div class="layui-inline">
                <input class="layui-input" name="account" id="eAccount" autocomplete="off">
            </div>
            &nbsp&nbsp&nbsp
            部门：
            <div class="layui-inline">
                <!--<input class="layui-input" name="id" id="dId" autocomplete="off">-->
                <!--<div class="layui-input-inline">-->
                <!--<select name="dep" id="dId" lay-verify="required" lay-search="">-->
                <!--<option value="">直接选择或搜索选择</option>-->
                <!--</select>-->
                <!--</div>-->
                <div class="layui-form-item">
                    <div class="layui-input-block" style="width: 157px;margin: 13px 0 0 0;">
                        <select name="dep" id="dId" lay-filter="">
                            <option value=""></option>
                        </select>
                    </div>
                </div>
            </div>
            &nbsp&nbsp&nbsp
            考勤月份：
            <div class="layui-inline">
                <input name="d" id="date" lay-verify="date" autocomplete="off" class="layui-input" type="text" readonly>
            </div>
            &nbsp&nbsp&nbsp
            <button class="layui-btn" data-type="reload">搜索</button>
        </div>
        <div class="layui-col-md1  demoTable">
            <div class="layui-inline">
                <button class="layui-btn layui-btn-danger" data-type="getCheckLength"
                        style=" margin-top: 14px;padding: 2px 10px 4px 10px">批量删除
                </button>
            </div>
        </div>
    </div>

</div>


</div>
<!--<xblock>-->
<!--<button class="layui-btn" onclick="x_admin_show('添加','toPage.do?url=admin/monthlyattendance-add.html',600,400)"><i class="layui-icon"></i>添加</button>-->
<!--</xblock>-->


<div style="text-align: center">
    <table class="layui-table"
           lay-data="{height: 'full-160', cellMinWidth:80, url:'monthlyattendance/findSelective.do', page:true, id:'idTest'}"
           lay-filter="demo">
        <thead>
        <tr>
            <th lay-data="{type:'checkbox', fixed: 'left'}" , rowspan="2"></th>
            <th lay-data="{field:'attendanceTime', templet: '<span>{{d.monthlyAttendance.attendanceTime}}</span>', width:100, fixed: true,align: 'center'}"
                rowspan="2">月份
            </th>
            <th lay-data="{field:'eName', templet: '<span>{{d.employee.eName}}</span>',fixed: 'left',minWidth:100,align: 'center'}"
                rowspan="2">姓名
            </th>
            <th lay-data="{minWidth:100,align: 'center'}" colspan="2">员工信息</th>
            <th lay-data="{minWidth:100,align: 'center'}" colspan="2">请假天数</th>
            <th lay-data="{minWidth:100,align: 'center'}" colspan="3">加班小时</th>
            <th lay-data="{minWidth:100,align: 'center'}" colspan="4">考勤情况</th>
            <th lay-data="{fixed: 'right', width:130, align:'center', toolbar: '#barDemo'}" rowspan="2"></th>
        </tr>
        <tr>
            <th lay-data="{field:'eAccount', templet: '<span>{{d.employee.eAccount}}</span>',minWidth:100,align: 'center'}"
                rowspan="2">工号
            </th>
            <th lay-data="{field:'dName', templet: '<span>{{d.department.dName}}</span>',minWidth:100,align: 'center'}"
                rowspan="2">部门
            </th>

            <th lay-data="{field:'sickLeaveNum', templet: '<span>{{d.monthlyAttendance.sickLeaveNum}}</span>', minWidth:100,align: 'center'}">
                病假
            </th>
            <th lay-data="{field:'compassionateLeaveNum', templet: '<span>{{d.monthlyAttendance.compassionateLeaveNum}}</span>', minWidth:100,align: 'center'}">
                事假
            </th>

            <th lay-data="{field:'overtimeHour', templet: '<span>{{d.monthlyAttendance.overtimeHour}}</span>', minWidth:100,align: 'center'}">
                平时加班
            </th>
            <th lay-data="{field:'weekendHour', templet: '<span>{{d.monthlyAttendance.weekendHour}}</span>', minWidth:100,align: 'center'}">
                周末加班
            </th>
            <th lay-data="{field:'holidayHour', templet: '<span>{{d.monthlyAttendance.holidayHour}}</span>', minWidth:100,align: 'center'}">
                节假日加班
            </th>

            <th lay-data="{field:'lateNum', templet: '<span>{{d.monthlyAttendance.lateNum}}</span>', minWidth:100,align: 'center'}">
                迟到次数
            </th>
            <th lay-data="{field:'earlyNum', templet: '<span>{{d.monthlyAttendance.earlyNum}}</span>', minWidth:100,align: 'center'}">
                早退次数
            </th>
            <th lay-data="{field:'absenceNum', templet: '<span>{{d.monthlyAttendance.absenceNum}}</span>', minWidth:100,align: 'center'}">
                缺勤天数
            </th>
            <th lay-data="{field:'businessTravelNum', templet: '<span>{{d.monthlyAttendance.businessTravelNum}}</span>', minWidth:100,align: 'center'}">
                出差天数
            </th>
        </tr>
        </thead>
    </table>
</div>

</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>

    window.onload = function () {
        //加载部门下拉搜索框
        var dId = $("#dId");
        $.ajax({
            url: 'department/findSelective.do?page=1&limit=999', //分页限制为999条，就是全部
            dataType: 'json',
            type: 'post',
            success: function (result) {
                // console.log(result);
                $.each(result.data, function (index, item) {
                    // console.log(index + "&" + item.dId);
                    dId.append("<option value=" + item.dId + ">" + item.dName + "</option>");// 下拉菜单里添加元素
                })
                layui.form.render('select');  //渲染select
            }
        });
    }

    // 刷新(主要用于批量删除，不能直接在里面刷新，那样会使操作失败，要跳出来执行)
    function myReload() {
        location.replace(location.href);
    }

    layui.use(['form', 'layedit', 'laydate', 'table'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , table = layui.table;

        //年月范围
        laydate.render({
            elem: '#date'
            , type: 'month'
        });

        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('确定要删除吗', function (index) {
                    // console.log(data.monthlyAttendance);
                    $.ajax({
                        type: 'post',
                        url: 'monthlyattendance/deleteByPrimaryKey.do',
                        data: {"id": data.monthlyAttendance.maId},
                        dataType: 'json',
                        success: function (data) {
                            if (data == 1) {
                                layer.msg('已删除!', {icon: 1, time: 4000});
                                // $(obj).parents("tr").remove();
                                obj.del();

                            }
                            else {
                                //alert("exist");
                                layer.msg('删除失败!', {icon: 5, time: 1000});
                            }
                        },
                        error: function (data) {
                            // alert("error" + data);
                            layer.alert("抱歉！出现未知错误！", {icon: 5});
                        }

                    });
                    obj.del();
                    layer.close(index);
                    // location.reload();
                });
            } else if (obj.event === 'edit') {
                // layer.alert('编辑行：<br>'+ JSON.stringify(data));
                x_admin_show('编辑', 'toPage.do?url=admin/monthlyattendance-edit.html?maId=' + data.monthlyAttendance.maId + '&eAccount=' + data.employee.eAccount + '&dName=' + data.department.dName, 1050, 600);

            }
        });

        var $ = layui.$, active = {

            reload: function () {
                var eAccount = $('#eAccount');
                var dId = $('#dId');
                var date = $('#date');
                // alert("asd");
                // console.log(eAccount.val()+" "+dId.val()+" "+date.val());
                // 执行重载
                table.reload('idTest', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        e_account: eAccount.val(),
                        d_id: dId.val(),
                        attendance_time: date.val()
                    }
                });
            },
            getCheckLength: function () { //获取选中数目
                var checkStatus = table.checkStatus('idTest')
                    , data = checkStatus.data;
                //遍历选中的选项中的id，放到数组中
                var ids = [];
                $.each(data, function (index, item) {
                    // console.log(item.employee.eId);
                    ids.push(item.monthlyAttendance.maId);
                });

                layer.confirm('确定要删除吗', function (index) {

                    $.ajax({
                        type: 'post',
                        url: 'monthlyattendance/deleteByQuery.do',
                        data: {"arr": ids},
                        traditional: true,
                        dataType: 'json',
                        success:function(data) {
                            if (data == 1) {
                                layer.msg('已删除!', {icon: 1, time: 4000});
                                // $(obj).parents("tr").remove();
                                // obj.del();
                            }
                            else {
                                //alert("exist");
                                layer.msg('删除失败!', {icon: 5, time: 1000});
                            }
                        },
                        error: function (data) {
                            // alert("error" + data);
                            layer.alert("抱歉！出现未知错误！", {icon: 5});
                        }
                    });
                    // obj.del();
                    layer.close(index);
                    // myReload();
                    relo();
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        function relo() {
            var eAccount = $('#eAccount');
            var dId = $('#dId');
            var date = $('#date');
            // alert("asd");
            // console.log(eAccount.val()+" "+dId.val()+" "+date.val());
            // 执行重载
            table.reload('idTest', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    e_account: eAccount.val(),
                    d_id: dId.val(),
                    attendance_time: date.val()
                }
            });
        }

    });

</script>

</body>

</html>